package cn.dengta.webapp.user.entity;

import java.util.Date;

import cn.dengta.webapp.base.entity.BizEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 用户活动账号
 *
 * @author lgy
 * @since 2022-10-13
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("act_user_asset")
public class ActUserAsset extends BizEntity {

	/** 用户ID */
	Long userId;
	/** 活动ID */
	Long activityId;
	/** 总次数 */
	Integer totalCount;
	/** 已使用次数 */
	Integer usedCount;

	public ActUserAsset init(Long userId, Long activityId, Date now) {
		this.userId = userId;
		this.activityId = activityId;
		this.totalCount = 0;
		this.usedCount = 0;
		super.initActiveStatus();
		super.initTime(now);
		return this;
	}

	public Integer addUsedCount() {
		return ++usedCount;
	}

	public Integer getActiveCount() {
		return totalCount - usedCount;
	}

	public boolean hasRemain() {
		return totalCount > usedCount;
	}

	public static final String USER_ID = "user_id";
	public static final String ACTIVITY_ID = "activity_id";
	public static final String TOTAL_COUNT = "total_count";
	public static final String USED_COUNT = "used_count";

}
